{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Raccoon vs. Pandas speed test\n",
    "============================="
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Setup pythonpath, import libraries and initialized DataFrame to store results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Use this statement to import the current development version\n",
    "import sys; sys.path.insert(0, '../')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [],
   "source": [
    "from copy import deepcopy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [],
   "source": [
    "import raccoon as rc\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Machine information\n",
    "--------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AMD64\n",
      "Intel64 Family 6 Model 142 Stepping 10, GenuineIntel\n",
      "Windows-10-10.0.18362-SP0\n",
      "python  3.7.4\n"
     ]
    }
   ],
   "source": [
    "import platform\n",
    "print(platform.machine())\n",
    "print(platform.processor())\n",
    "print(platform.platform())\n",
    "print(\"python \", platform.python_version())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Run the Speed Test\n",
    "----"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "results = rc.DataFrame(columns=['raccoon', 'pandas', 'ratio'], sort=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "def add_results(index):\n",
    "    results[index, 'raccoon'] = res_rc.best\n",
    "    results[index, 'pandas'] = res_pd.best\n",
    "    results[index, 'ratio'] = res_rc.best / res_pd.best"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index    raccoon    pandas    ratio\n",
      "-------  ---------  --------  -------\n",
      "version  3.0.0      0.25.2\n"
     ]
    }
   ],
   "source": [
    "results['version', 'raccoon'] = rc.__version__\n",
    "results['version', 'pandas'] = pd.__version__\n",
    "print(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Initialize 10,000 empty DataFrames\n",
    "---------------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "def init_rc():\n",
    "    for x in range(10000):\n",
    "        df = rc.DataFrame()\n",
    "        \n",
    "def init_pd():\n",
    "    for x in range(10000):\n",
    "        df = pd.DataFrame()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "88.7 ms ± 6.1 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o init_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.49 s ± 155 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o init_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('initialize empty')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index             raccoon              pandas                 ratio\n",
      "----------------  -------------------  -----------------  ---------\n",
      "version           3.0.0                0.25.2\n",
      "initialize empty  0.08248082999998588  4.237655099999756  0.0194638\n"
     ]
    }
   ],
   "source": [
    "results.print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Initialize 100 row X 100 col DataFrame()\n",
    "--------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = dict()\n",
    "for x in range(100):\n",
    "    data['a' + str(x)] = list(range(100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "121 µs ± 7.92 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o df=rc.DataFrame(data=data, sort=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15.3 ms ± 279 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o df=pd.DataFrame(data=data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('initialize with matrix')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                   raccoon                pandas                     ratio\n",
      "----------------------  ---------------------  --------------------  ----------\n",
      "version                 3.0.0                  0.25.2\n",
      "initialize empty        0.08248082999998588    4.237655099999756     0.0194638\n",
      "initialize with matrix  0.0001130529800000204  0.014922300999996878  0.00757611\n"
     ]
    }
   ],
   "source": [
    "results.print()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Add 10,000 items in 1 column to empty DataFrame\n",
    "-------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "def one_col_add_rc():\n",
    "    df = rc.DataFrame()\n",
    "    for x in range(10000):\n",
    "        df.set(x, 'a', x)\n",
    "        \n",
    "def one_col_add_pd():\n",
    "    df = pd.DataFrame()\n",
    "    for x in range(10000):\n",
    "        df.at[x, 'a'] = x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "53.7 ms ± 2.67 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o one_col_add_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17.1 s ± 193 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o one_col_add_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('add rows one column')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                   raccoon                pandas                     ratio\n",
      "----------------------  ---------------------  --------------------  ----------\n",
      "version                 3.0.0                  0.25.2\n",
      "initialize empty        0.08248082999998588    4.237655099999756     0.0194638\n",
      "initialize with matrix  0.0001130529800000204  0.014922300999996878  0.00757611\n",
      "add rows one column     0.050407570000015764   16.86793469999975     0.00298837\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Add 100 rows of 100 columns to empty DataFrame\n",
    "----------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_row = {('a' + str(x)): x for x in range(100)}\n",
    "columns = ['a' + str(x) for x in range(100)]\n",
    "\n",
    "def matrix_add_rc():\n",
    "    df = rc.DataFrame(columns=columns)\n",
    "    for x in range(100):\n",
    "        df.set(indexes=x, values=new_row)\n",
    "\n",
    "def matrix_add_pd():\n",
    "    df = pd.DataFrame(columns=columns)\n",
    "    for x in range(100):\n",
    "        df.loc[x] = new_row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 ms ± 185 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o matrix_add_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "296 ms ± 4.94 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o matrix_add_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('add matrix')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                   raccoon                pandas                     ratio\n",
      "----------------------  ---------------------  --------------------  ----------\n",
      "version                 3.0.0                  0.25.2\n",
      "initialize empty        0.08248082999998588    4.237655099999756     0.0194638\n",
      "initialize with matrix  0.0001130529800000204  0.014922300999996878  0.00757611\n",
      "add rows one column     0.050407570000015764   16.86793469999975     0.00298837\n",
      "add matrix              0.009786346000000777   0.28846930000008797   0.0339251\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Append 10x10 DataFrame 1000 times\n",
    "------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [],
   "source": [
    "def append_rc():\n",
    "    grid = {'a' + str(x): [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for x in range(10)}\n",
    "    df = rc.DataFrame(data=deepcopy(grid), columns=list(grid.keys()))\n",
    "    for x in range(100):\n",
    "        index = [(y + 1) + (x + 1) * 10 for y in range(10)]\n",
    "        new_grid = deepcopy(grid)\n",
    "        new_df = rc.DataFrame(data=new_grid, columns=list(new_grid.keys()), index=index)\n",
    "        df.append(new_df)\n",
    "\n",
    "def append_pd():\n",
    "    grid = {'a' + str(x): [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for x in range(10)}\n",
    "    df = pd.DataFrame(data=grid, columns=list(grid.keys()))\n",
    "    for x in range(100):\n",
    "        index = [(y + 1) + (x + 1) * 10 for y in range(10)]\n",
    "        new_grid = deepcopy(grid)\n",
    "        new_df = pd.DataFrame(data=new_grid, columns=list(new_grid.keys()), index=index)\n",
    "        df = df.append(new_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "77.5 ms ± 3.77 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o append_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "370 ms ± 19.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o append_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('append')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                   raccoon                pandas                     ratio\n",
      "----------------------  ---------------------  --------------------  ----------\n",
      "version                 3.0.0                  0.25.2\n",
      "initialize empty        0.08248082999998588    4.237655099999756     0.0194638\n",
      "initialize with matrix  0.0001130529800000204  0.014922300999996878  0.00757611\n",
      "add rows one column     0.050407570000015764   16.86793469999975     0.00298837\n",
      "add matrix              0.009786346000000777   0.28846930000008797   0.0339251\n",
      "append                  0.07348676999999952    0.346767699999873     0.211919\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Get\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [],
   "source": [
    "# First create a 1000 row X 100 col matrix for the test. Index is [0...999]\n",
    "\n",
    "col = [x for x in range(1000)]\n",
    "grid = {'a' + str(x): col[:] for x in range(100)}\n",
    "\n",
    "df_rc = rc.DataFrame(data=grid, columns=sorted(grid.keys()))\n",
    "df_pd = pd.DataFrame(data=grid, columns=sorted(grid.keys()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get cell\n",
    "\n",
    "def rc_get_cell():\n",
    "    for c in df_rc.columns:\n",
    "        for r in df_rc.index:\n",
    "            x = df_rc.get(r, c)\n",
    "            \n",
    "def pd_get_cell():\n",
    "    for c in df_pd.columns:\n",
    "        for r in df_pd.index:\n",
    "            x = df_pd.at[r, c]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "718 ms ± 45.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o rc_get_cell()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.02 s ± 71.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o pd_get_cell()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('get cell')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                   raccoon                pandas                     ratio\n",
      "----------------------  ---------------------  --------------------  ----------\n",
      "version                 3.0.0                  0.25.2\n",
      "initialize empty        0.08248082999998588    4.237655099999756     0.0194638\n",
      "initialize with matrix  0.0001130529800000204  0.014922300999996878  0.00757611\n",
      "add rows one column     0.050407570000015764   16.86793469999975     0.00298837\n",
      "add matrix              0.009786346000000777   0.28846930000008797   0.0339251\n",
      "append                  0.07348676999999952    0.346767699999873     0.211919\n",
      "get cell                0.6728431999999884     0.9376910000000862    0.717553\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get column all index\n",
    "\n",
    "def get_column_all_rc():\n",
    "    for c in df_rc.columns:\n",
    "        x = df_rc.get(columns=c)\n",
    "        \n",
    "def get_column_all_pd():\n",
    "    for c in df_pd.columns:\n",
    "        x = df_pd[c]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42.8 ms ± 743 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o get_column_all_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "402 µs ± 24.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o get_column_all_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('get column all index')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                   raccoon                pandas                        ratio\n",
      "----------------------  ---------------------  ---------------------  ------------\n",
      "version                 3.0.0                  0.25.2\n",
      "initialize empty        0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix  0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column     0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix              0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                  0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index    0.041298069999993456   0.0003524336000000403  117.18\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get subset of the index of the column\n",
    "\n",
    "def get_column_subset_rc():\n",
    "    for c in df_rc.columns:\n",
    "        for r in range(100):\n",
    "            rows = list(range(r*10, r*10 + 9))\n",
    "            x = df_rc.get(indexes=rows, columns=c)\n",
    "        \n",
    "def get_column_subset_pd():\n",
    "    for c in df_pd.columns:\n",
    "        for r in range(100):\n",
    "            rows = list(range(r*10, r*10 + 9))\n",
    "            x = df_pd.loc[rows, c]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "609 ms ± 62.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o get_column_subset_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.1 s ± 40.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o get_column_subset_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('get column subset index')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get index all columns\n",
    "\n",
    "def get_index_all_rc():\n",
    "    for i in df_rc.index:\n",
    "        x = df_rc.get(indexes=i)\n",
    "        \n",
    "def get_index_all_pd():\n",
    "    for i in df_pd.index:\n",
    "        x = df_pd.loc[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.07 s ± 27.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o get_index_all_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "229 ms ± 9.34 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o get_index_all_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('get index all columns')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n",
      "get index all columns    1.0389918000000762     0.2065747999999985       5.02962\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Set\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [],
   "source": [
    "# First create a 1000 row X 100 col matrix for the test. Index is [0...999]\n",
    "\n",
    "col = [x for x in range(1000)]\n",
    "grid = {'a' + str(x): col[:] for x in range(100)}\n",
    "\n",
    "df_rc = rc.DataFrame(data=grid, columns=sorted(grid.keys()))\n",
    "df_pd = pd.DataFrame(data=grid, columns=sorted(grid.keys()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set cell\n",
    "\n",
    "def rc_set_cell():\n",
    "    for c in df_rc.columns:\n",
    "        for r in df_rc.index:\n",
    "            df_rc.set(r, c, 99)\n",
    "            \n",
    "def pd_set_cell():\n",
    "    for c in df_pd.columns:\n",
    "        for r in df_pd.index:\n",
    "            df_pd.at[r, c] = 99"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "578 ms ± 33.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o rc_set_cell()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.36 s ± 65.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o pd_set_cell()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('set cell')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n",
      "get index all columns    1.0389918000000762     0.2065747999999985       5.02962\n",
      "set cell                 0.5282995000002302     1.26670009999998         0.417068\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set column all index\n",
    "\n",
    "def set_column_all_rc():\n",
    "    for c in df_rc.columns:\n",
    "        x = df_rc.set(columns=c, values=99)\n",
    "        \n",
    "def set_column_all_pd():\n",
    "    for c in df_pd.columns:\n",
    "        x = df_pd[c] = 99"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.84 ms ± 512 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o set_column_all_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17.2 ms ± 516 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o set_column_all_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('set column all index')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n",
      "get index all columns    1.0389918000000762     0.2065747999999985       5.02962\n",
      "set cell                 0.5282995000002302     1.26670009999998         0.417068\n",
      "set column all index     0.00548794899999848    0.01662835399999949      0.330036\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set subset of the index of the column\n",
    "\n",
    "def set_column_subset_rc():\n",
    "    for c in df_rc.columns:\n",
    "        for r in range(100):\n",
    "            rows = list(range(r*10, r*10 + 10))\n",
    "            x = df_rc.set(indexes=rows, columns=c, values=list(range(10)))\n",
    "        \n",
    "def set_column_subset_pd():\n",
    "    for c in df_pd.columns:\n",
    "        for r in range(100):\n",
    "            rows = list(range(r*10, r*10 + 10))\n",
    "            x = df_pd.loc[rows, c] = list(range(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "380 ms ± 7.21 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o set_column_subset_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "59 s ± 732 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o set_column_subset_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('set column subset index')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n",
      "get index all columns    1.0389918000000762     0.2065747999999985       5.02962\n",
      "set cell                 0.5282995000002302     1.26670009999998         0.417068\n",
      "set column all index     0.00548794899999848    0.01662835399999949      0.330036\n",
      "set column subset index  0.37289839999994       58.03955229999974        0.0064249\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [],
   "source": [
    "row = {x:x for x in grid.keys()}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set index all columns\n",
    "\n",
    "def set_index_all_rc():\n",
    "    for i in df_rc.index:\n",
    "        x = df_rc.set(indexes=i, values=row)\n",
    "        \n",
    "def set_index_all_pd():\n",
    "    for i in df_pd.index:\n",
    "        x = df_pd.loc[i] = row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "64.4 ms ± 513 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o set_index_all_rc()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.41 s ± 15.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o set_index_all_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('set index all columns')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n",
      "get index all columns    1.0389918000000762     0.2065747999999985       5.02962\n",
      "set cell                 0.5282995000002302     1.26670009999998         0.417068\n",
      "set column all index     0.00548794899999848    0.01662835399999949      0.330036\n",
      "set column subset index  0.37289839999994       58.03955229999974        0.0064249\n",
      "set index all columns    0.06374265999997988    1.390037300000131        0.0458568\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Sort\n",
    "-----"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [],
   "source": [
    "# make a dataframe 1000x100 with index in reverse order\n",
    "\n",
    "rev = list(reversed(range(1000)))\n",
    "\n",
    "df_rc = rc.DataFrame(data=grid, index=rev)\n",
    "df_pd = pd.DataFrame(grid, index=rev)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16 ms ± 953 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o df_rc.sort_index() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "859 µs ± 12.6 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o df_pd.sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('sort index')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n",
      "get index all columns    1.0389918000000762     0.2065747999999985       5.02962\n",
      "set cell                 0.5282995000002302     1.26670009999998         0.417068\n",
      "set column all index     0.00548794899999848    0.01662835399999949      0.330036\n",
      "set column subset index  0.37289839999994       58.03955229999974        0.0064249\n",
      "set index all columns    0.06374265999997988    1.390037300000131        0.0458568\n",
      "sort index               0.014900102999999944   0.0008343847000001006   17.8576\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Iterators\n",
    "---------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [],
   "source": [
    "# First create a 1000 row X 100 col matrix for the test. Index is [0...999]\n",
    "\n",
    "col = [x for x in range(1000)]\n",
    "grid = {'a' + str(x): col[:] for x in range(100)}\n",
    "\n",
    "df_rc = rc.DataFrame(data=grid, columns=sorted(grid.keys()))\n",
    "df_pd = pd.DataFrame(data=grid, columns=sorted(grid.keys()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [],
   "source": [
    "# iterate over the rows\n",
    "\n",
    "def iter_rc():\n",
    "    for row in df_rc.iterrows():\n",
    "        x = row\n",
    "        \n",
    "def iter_pd():\n",
    "    for row in df_pd.itertuples():\n",
    "        x = row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "27.2 ms ± 381 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o iter_rc() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "34 ms ± 532 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o iter_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('iterate rows')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n",
      "get index all columns    1.0389918000000762     0.2065747999999985       5.02962\n",
      "set cell                 0.5282995000002302     1.26670009999998         0.417068\n",
      "set column all index     0.00548794899999848    0.01662835399999949      0.330036\n",
      "set column subset index  0.37289839999994       58.03955229999974        0.0064249\n",
      "set index all columns    0.06374265999997988    1.390037300000131        0.0458568\n",
      "sort index               0.014900102999999944   0.0008343847000001006   17.8576\n",
      "iterate rows             0.026519559999997      0.03318497000000207      0.799144\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Insert in the middle\n",
    "--------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [],
   "source": [
    "# First create a 500 row X 100 col matrix for the test. Index is [1, 3, 5, 7,...500] every other\n",
    "\n",
    "col = [x for x in range(1, 1000, 2)]\n",
    "grid = {'a' + str(x): col[:] for x in range(100)}\n",
    "\n",
    "df_rc = rc.DataFrame(data=grid, columns=sorted(grid.keys()), sort=True)\n",
    "df_pd = pd.DataFrame(data=grid, columns=sorted(grid.keys()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {},
   "outputs": [],
   "source": [
    "row = {x:x for x in grid.keys()}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set index all columns\n",
    "\n",
    "def insert_rows_rc():\n",
    "    for i in range(0, 999, 2):\n",
    "        x = df_rc.set(indexes=i, values=row)\n",
    "        \n",
    "def insert_rows_pd():\n",
    "    for i in range(0, 999, 2):\n",
    "        x = df_pd.loc[i] = row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "33 ms ± 3.08 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o insert_rows_rc() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "723 ms ± 30.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o insert_rows_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('insert rows')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n",
      "get index all columns    1.0389918000000762     0.2065747999999985       5.02962\n",
      "set cell                 0.5282995000002302     1.26670009999998         0.417068\n",
      "set column all index     0.00548794899999848    0.01662835399999949      0.330036\n",
      "set column subset index  0.37289839999994       58.03955229999974        0.0064249\n",
      "set index all columns    0.06374265999997988    1.390037300000131        0.0458568\n",
      "sort index               0.014900102999999944   0.0008343847000001006   17.8576\n",
      "iterate rows             0.026519559999997      0.03318497000000207      0.799144\n",
      "insert rows              0.030685470000025816   0.6862636999999268       0.0447138\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Time Series Append\n",
    "------------------\n",
    "Simulate the recording of a stock on 1 minute intervals and appending to the DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_row = {'open': 100, 'high': 101, 'low': 99, 'close': 100.5, 'volume': 999}\n",
    "\n",
    "dates = pd.date_range('2010-01-01 09:30:00', periods=10000, freq='1min')\n",
    "\n",
    "def time_series_rc():\n",
    "    ts = rc.DataFrame(columns=['open', 'high', 'low', 'close', 'volume'], index_name='datetime', sort=True)\n",
    "    for date in dates:\n",
    "        ts.set_row(date, data_row)\n",
    "\n",
    "def time_series_pd():\n",
    "    ts = pd.DataFrame(columns=['open', 'high', 'low', 'close', 'volume'])\n",
    "    for date in dates:\n",
    "        ts.loc[date] = data_row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "134 ms ± 4.28 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
     ]
    }
   ],
   "source": [
    "res_rc = %timeit -o time_series_rc() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "29.4 s ± 124 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
     ]
    }
   ],
   "source": [
    "res_pd = %timeit -o time_series_pd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [],
   "source": [
    "add_results('time series')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index                    raccoon                pandas                        ratio\n",
      "-----------------------  ---------------------  ---------------------  ------------\n",
      "version                  3.0.0                  0.25.2\n",
      "initialize empty         0.08248082999998588    4.237655099999756        0.0194638\n",
      "initialize with matrix   0.0001130529800000204  0.014922300999996878     0.00757611\n",
      "add rows one column      0.050407570000015764   16.86793469999975        0.00298837\n",
      "add matrix               0.009786346000000777   0.28846930000008797      0.0339251\n",
      "append                   0.07348676999999952    0.346767699999873        0.211919\n",
      "get cell                 0.6728431999999884     0.9376910000000862       0.717553\n",
      "get column all index     0.041298069999993456   0.0003524336000000403  117.18\n",
      "get column subset index  0.5668462000003274     7.041264400000273        0.0805035\n",
      "get index all columns    1.0389918000000762     0.2065747999999985       5.02962\n",
      "set cell                 0.5282995000002302     1.26670009999998         0.417068\n",
      "set column all index     0.00548794899999848    0.01662835399999949      0.330036\n",
      "set column subset index  0.37289839999994       58.03955229999974        0.0064249\n",
      "set index all columns    0.06374265999997988    1.390037300000131        0.0458568\n",
      "sort index               0.014900102999999944   0.0008343847000001006   17.8576\n",
      "iterate rows             0.026519559999997      0.03318497000000207      0.799144\n",
      "insert rows              0.030685470000025816   0.6862636999999268       0.0447138\n",
      "time series              0.13054121000000124    29.182044600000154       0.00447334\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:.conda-raccoon]",
   "language": "python",
   "name": "conda-env-.conda-raccoon-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
